
//
//  FkNavViewController.swift
//  FireKnowledge
//
//  Created by 杨伟毅 on 2019/4/19.
//  Copyright © 2019 wely. All rights reserved.
//

import UIKit

class FkNavViewController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate  =  nil
        initNavBar()
        // Do any additional setup after loading the view.
    }
    func initNavBar() -> Void {
        let navBar = UINavigationBar.appearance()
        navBar.barTintColor = .white
        navBar.isTranslucent = false
        navBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.black]
        navBar.shadowImage = UIImage()
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.children.count > 0 {
            let button = UIButton(type: .system)
            button.setImage(UIImage.init(named: "back")?.withRenderingMode(.alwaysOriginal), for: .normal)
            button.frame = FKRect(x: 0, y: 0, width: 20, height: 20)
            let view = UIView() // 解决点击区域过大
            view.frame = FKRect(x: 0, y:FKScreenBound.StatusH, width: 20, height: 20)
            view.addSubview(button)
            button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: view)
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    @objc func buttonAction() {
        self.popViewController(animated: true)
    }
    
    override var shouldAutorotate: Bool {
        return self.viewControllers.last!.shouldAutorotate
    }
    
    override  var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        
        return self.viewControllers.last!.supportedInterfaceOrientations
    }
    
    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return self.viewControllers.last!.preferredInterfaceOrientationForPresentation
    }
    
    
    
    
    
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
